package com.twu.biblioteca.user;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Enrico on 17/09/2014.
 */
public class Users {

    private List<User> users;

    public Users() {
        users = new ArrayList<User>();
        addUsers();
    }

    public Users(List<User> users) {
        this.users = users;
    }

    public void addUsers() {
        for (int i = 1; i < 10; i++) {
            users.add(new User("A00-000" + i, "enrico000" + i, "enrico" + i, "enrico" + i + ".caporali@gmail.com",
                    "0420774402"));
        }
    }

    public void add(User user) {
        if (user == null) throw new NullPointerException("User cannot be null");
        users.add(user);
    }

    public boolean isEmpty() {
        return this.users.isEmpty();
    }


    public User lookup(String libraryNo, String password) {
        for (User user : users) {
            if (user.matches(libraryNo, password)) {
                return user;
            }
        }
        return null;
    }
}
